package br.com.dev.tcc.adapter;

import java.util.List;

import br.com.dev.tcc.R;
import br.com.dev.tcc.bean.MapLocal;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListaLocaisAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private List<MapLocal> locais;
	
	public ListaLocaisAdapter(Context ctx, List<MapLocal> locais){
		
		this.locais = locais;
		this.inflater = LayoutInflater.from(ctx);
	}
	
	@Override
	public int getCount() {
		return locais.size();
	}

	@Override
	public Object getItem(int position) {
		return locais.get(position);
	}

	@Override
	public long getItemId(int id) {
		return id;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {

		MapLocal local = locais.get(position);
		
		ViewHolder holder = null;
		
		if(convertView == null){
			
			convertView = inflater.inflate(R.layout.mapa_itens, null);
		
			holder = new ViewHolder();
			holder.txtNomeLocal = ((TextView) convertView.findViewById(R.id.txtNomeLocal));
			holder.txtEnderecoLocal = ((TextView) convertView.findViewById(R.id.txtLocal));
			
			convertView.setTag(holder);
		}
		else{

			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.txtNomeLocal.setText(local.getName());
		holder.txtEnderecoLocal.setText(local.getAddress());
		
		return convertView;
	}
	
	private class ViewHolder {
		
		TextView txtNomeLocal;
		TextView txtEnderecoLocal;
	}
}
